package com.yvon.maple.service.auth.domain;

import com.yvon.maple.cloud.api.system.dto.SecurityUserDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;


/**
 * Created by macro on 2019/8/29.
 *
 * @author : Yvon
 * @since : 2021-08-25
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class SecurityUser extends User implements Serializable {

    /**
     * ID
     */
    private Long id;

    private String avatar;

    private String phone;

    private String nickname;

    private Boolean isAdmin;

    public SecurityUser(SecurityUserDTO securityUserDTO, Collection<? extends GrantedAuthority> authorities) {
        super(securityUserDTO.getUsername(),
                Objects.isNull(securityUserDTO.getPassword()) ? "12345" : securityUserDTO.getPassword() ,
                securityUserDTO.getEnabled(),
                securityUserDTO.getAccountNonExpired(),
                securityUserDTO.getCredentialsNonExpired(),
                securityUserDTO.getAccountNonLocked(),
                authorities);
        this.id = securityUserDTO.getId();
    }
}
